﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using EpiNEXT.Services.Fields;

namespace EpiNEXT.Services.Validation
{
    //[Serializable()]
    public abstract class ConditionBase : ICondition
    {
        private string _positionString = "L";
        private TokenPositions _position = TokenPositions.Left;

        [XmlIgnore]
        public TokenPositions Position
        {
            get { return this._position; }
            set
            {
                if (Position != value)
                {
                    this._position = value;
                    switch (Position)
                    {
                        default:
                        case TokenPositions.Left:
                            PositionString = "L";
                            break;
                        case TokenPositions.Right:
                            PositionString = "R";
                            break;
                        case TokenPositions.Center:
                            PositionString = "C";
                            break;
                    }
                }
            }
        }

        [XmlAttribute("Pos")]
        public string PositionString
        {
            get { return this._positionString; }
            set
            {
                if (!PositionString.Equals(value))
                {
                    this._positionString = value;
                    switch (PositionString)
                    {
                        default:
                        case "L":
                            Position = TokenPositions.Left;
                            break;
                        case "C":
                            Position = TokenPositions.Center;
                            break;
                        case "R":
                            Position = TokenPositions.Right;
                            break;
                    }
                }
            }
        }

        public abstract bool Evaluate(Record record);

        public abstract List<IField> GetFieldsInCondition(DataEntryInstrument form);
    }
}
